package com.google.android.apps.iosched.ui;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.google.android.apps.iosched.R;
import com.google.android.apps.iosched.util.BeamUtils;

/**
 * Created by Alex on 13-12-5.
 */
public class BeamActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_beam);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (BeamUtils.wasLauchedThroughBeamFirstTime(this,getIntent())){
            BeamUtils.setBeamUnlocked(this);
            showUnlockDialog();
        }
    }

    private void showUnlockDialog(){
        new AlertDialog.Builder(this)
                .setTitle(R.string.just_beamed)
                .setMessage(R.string.beam_unlocked_default)
                .setNegativeButton(R.string.close,null)
                .setPositiveButton(R.string.view_beam_session,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                BeamUtils.launchBeamSession(BeamActivity.this);
                                dialogInterface.dismiss();
                            }
                        }
                        ).create().show();
    }

    void showHelpDialog(){
        new AlertDialog.Builder(this)
                .setTitle(R.string.title_beam)
                .setMessage(R.string.beam_unlocked_help)
                .setNegativeButton(R.string.close,null)
                .setPositiveButton(R.string.view_beam_session,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                BeamUtils.launchBeamSession(BeamActivity.this);
                                dialogInterface.dismiss();
                            }
                        }
                        ).create().show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getSupportMenuInflater().inflate(R.menu.beam,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == R.id.menu_beam_help){
            showHelpDialog();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
